/**
 *  Copyright (C) 2006 zhangbo (freeeob@gmail.com)
 *
 *  This product is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 * 
 *  This product is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 *  author:zhangbo
 *  Email:jsjava@gmail.com
 */

/**
 * Constructor
 */
function WindowUtils(){
	this.jsjava_class="jsorg.eob.window.WindowUtils";
}

WindowUtils.TOP=0;
WindowUtils.RIGHT=1;
WindowUtils.BOTTOM=2;
WindowUtils.LEFT=3;
WindowUtils.TOP_LEFT=4;
WindowUtils.TOP_RIGHT=5;
WindowUtils.BOTTOM_LEFT=6;
WindowUtils.BOTTOM_RIGHT=7;
WindowUtils.CENTER=8;

/**
 * Maximize the specified window
 * @param winObj
 * @param isLeftTitleBar
 */
WindowUtils.maximize=function(winObj,isLeftTitleBar){
	var titlebar_height=30;
	if(isLeftTitleBar==true){
		titlebar_height=0;
	}
	var border_width=4;
	var availHeight=winObj.screen.availHeight + titlebar_height; 
	var availWidth=winObj.screen.availWidth + 2 * border_width;    
	winObj.resizeTo(availWidth,availHeight);
	winObj.moveBy(-border_width,-titlebar_height);
};

/**
 * Get the size of specified window
 * @param winObj
 */
WindowUtils.getSize=function(win){
	var myWidth = 0, myHeight = 0;
  	if( typeof( win.innerWidth ) == 'number' ) {
    	myWidth = win.innerWidth;
    	myHeight = win.innerHeight;
  	} else if( win.document.documentElement && ( win.document.documentElement.offsetWidth || win.document.documentElement.offsetHeight ) ) {
    	myWidth = win.document.documentElement.offsetWidth;
    	myHeight = win.document.documentElement.offsetHeight;
  	} else if( win.document.body && ( win.document.body.offsetWidth || win.document.body.offsetHeight ) ) {
    	myWidth = win.document.body.offsetWidth;
    	myHeight = win.document.body.offsetHeight;
  	}
  	return [myWidth,myHeight];
};

/**
 * Show the specified window in specified position
 * @param win
 * @param align a constant value such as WindowUtils.TOP and so on
 * @param topBarHeight
 */
WindowUtils.showInPosition=function(win,align,topBarHeight){
	var al=align;
	if(isNaN(align)){
		al=WindowUtils.CENTER;
	}
	if(win==undefined){
		win=window;
	}
	if(isNaN(topBarHeight)){
		topBarHeight=0;
	}
	var screenWidth=screen.availWidth;
	var screenHeight=screen.availHeight;
	var arr=WindowUtils.getSize(win);
	var winWidth=arr[0];
	var winHeight=arr[1];
	winHeight=winHeight+topBarHeight;
	switch(al){
		case WindowUtils.TOP : win.moveTo(screenWidth/2-winWidth/2,0);break;
		case WindowUtils.RIGHT : win.moveTo(screenWidth-winWidth,screenHeight/2-winHeight/2);break;
		case WindowUtils.BOTTOM : win.moveTo(screenWidth/2-winWidth/2,screenHeight-winHeight);break;
		case WindowUtils.LEFT : win.moveTo(0,screenHeight/2-winHeight/2);break;
		case WindowUtils.TOP_LEFT : win.moveTo(0,0);break;
		case WindowUtils.TOP_RIGHT : win.moveTo(screenWidth-winWidth,0);break;
		case WindowUtils.BOTTOM_LEFT : win.moveTo(0,screenHeight-winHeight);break;
		case WindowUtils.BOTTOM_RIGHT : win.moveTo(screenWidth-winWidth,screenHeight-winHeight);break;
		case WindowUtils.CENTER : win.moveTo(screenWidth/2-winWidth/2,screenHeight/2-winHeight/2);break;
		default : win.moveTo(screenWidth/2-winWidth/2,screenHeight/2-winHeight/2);break;
	}
};